#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
const int N = 2e3 + 10;
typedef pair<int, int> pii;
vector<pii> edges[N];
int dist[N];
int cnt[N];
bool st[N];
int n, m;
bool spfa()
{
    memset(dist, 0x3f, sizeof(dist));
    memset(cnt, 0, sizeof(cnt));
    memset(st, 0, sizeof(st));
    dist[1] = 0;
    queue<int> q;
    q.push(1);
    st[1] = true;
    while (q.size())
    {
        int a = q.front();
        q.pop();
        st[a] = false;
        for (auto& e : edges[a])
        {
            int v = e.first;
            int w = e.second;
            if (dist[a] + w < dist[v])
            {
                dist[v] = dist[a] + w;
                cnt[v] = cnt[a] + 1;
                if (cnt[v] >= n)
                {
                    return true;
                }
                if (!st[v])
                {
                    q.push(v);
                    st[v] = true;
                }
            }
        }
    }
    return false;
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
        {
            edges[i].clear();
        }
        for (int i = 1; i <= m; i++)
        {
            int u, v, w;
            cin >> u >> v >> w;
            if (w >= 0)
            {
                edges[u].push_back({ v,w });
                edges[v].push_back({ u,w });
            }
            else
            {
                edges[u].push_back({ v,w });
            }
        }
        bool ret = spfa();
        if (ret == true)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}